//
//  RNTMapManager.m
//  ReactNativeDemo
//
//  Created by AceWei on 2017/8/16.
//  Copyright © 2017年 AceWei. All rights reserved.
//

#import "RNTMapManager.h"

#import "TestMapView.h"

#import <React/RCTBridge.h>           //进行通信的头文件
#import <React/RCTEventDispatcher.h>  //事件派发，不导入会引起Xcode警告


@interface RNTMapManager ()

//@property (assign, nonatomic) BOOL isChangeBackground;

//@property (nonatomic, strong) TestMapView *map;

@end

@implementation RNTMapManager

RCT_EXPORT_MODULE()
//RCT_EXPORT_VIEW_PROPERTY(pitchEnabled, BOOL)
//RCT_EXPORT_VIEW_PROPERTY(isChangeBackground, BOOL)

RCT_EXPORT_VIEW_PROPERTY(onClickBanner, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(pitchEnabled, BOOL)


RCT_EXPORT_METHOD(testNormalEvent:(NSString *)name forSomething:(NSString *)thing){
    
    NSString *info = [NSString stringWithFormat:@"Test: %@\nFor: %@", name, thing];
    
    NSLog(@"%@", info);
}


//RCT_EXPORT_VIEW_PROPERTY(onClickBanner, RCTBubblingEventBlock)


//- (UIView *)view
//{
//    self.map = [[TestMapView alloc] init];
//    
//    if (self.map.onClickBanner) {
//        self.map.onClickBanner = ^(){
//            NSLog(@"ddddddddddd");
//        };
//    }
//    
//    
//    return self.map;
//}


- (UIView *)view
{
//    [self.bridge.eventDispatcher sendInputEventWithName:@"onClickBanner" body:@{@"target": self.view.reactTag, @"value": @"value"}];
    
//    MKMapView *map = [[MKMapView alloc] init];
//    
//    UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
//    [map addSubview:btn];
//    
//    [btn setTitle:@"button" forState:UIControlStateNormal];
//    
//    btn.backgroundColor = [UIColor purpleColor];
//    
//    btn.frame = CGRectMake(50, 80, 100, 70);
//    
//    [btn addTarget:self
//            action:@selector(clickTap)
//  forControlEvents:UIControlEventTouchUpInside];
    
    
    TestMapView *map = [[TestMapView alloc] init];
    
    
    __weak TestMapView *weakMap = map;
    map.onClick = ^(){
        weakMap.onClickBanner(@{@"name": @"Linus"});
    };
    
    return map;
}


- (void)clickTap
{
    NSLog(@"click~~");
    
//    if (_onTap) {
//        _onTap(@{@"name": @"Ace"});
//    }
    
    
//    self.map.onClickBanner(@{
//                             @"target": self.map.reactTag,
//                             @"value": @"value"
//                             });
    
    
    [self.bridge.eventDispatcher sendInputEventWithName:@"onClickBanner" body:@{@"target": self.view.reactTag, @"value": @"value"}];
    
    
    
//    @{@"target": cycleScrollView.reactTag,
//      @"value": [NSNumber numberWithInteger:index+1]}
    
//    [self.bridge.eventDispatcher sendInputEventWithName:@"onTap" body:@{@"target": self.view.reactTag, @"value": @"value"}];
}

@end
